package com.truonghau.xmeasure.commons;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Handler;
import android.os.Message;
import android.widget.EditText;

import com.truonghau.smstoxls.R;

public class CommonUtils {
	
	public static void getValuesFromPopup(final Context context, String title, String sms, final Handler hl) {
		AlertDialog.Builder alert = new AlertDialog.Builder(context);
		alert.setTitle(title);
		alert.setMessage(sms);
		final EditText input = new EditText(context); 
		input.setSelection(input.getText().length());
		alert.setView(input);
		alert.setPositiveButton(context.getString(android.R.string.ok), new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton) {
					if(input.getText() != null && !"".equals(input.getText().toString().trim())){
						Message msg = new Message();
						msg.obj = input.getText().toString().trim();
						hl.sendMessage(msg);
					}
					
			}
		});
		alert.show();
	}
	public static void getEditNamePointInList(final Context context, String title, String sms, final int index, final int total, final Handler hl, String oldText) {
		AlertDialog.Builder alert = new AlertDialog.Builder(context);
		alert.setTitle(title);
		alert.setMessage(sms);
		final EditText input = new EditText(context); 
		input.setText(oldText);
		input.setSelection(input.getText().length());
		alert.setView(input);
		alert.setPositiveButton(context.getString(android.R.string.ok), new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton) {
					if(input.getText() != null && !"".equals(input.getText().toString().trim())){
						Message msg = new Message();
						msg.obj = input.getText().toString().trim();
						//
						msg.arg1 = index;
						msg.arg2 = total;
						//
						hl.sendMessage(msg);
					}
					
			}
		});
		alert.show();
	}

	

	
}
